package com.starblink.message

import android.content.Context
import com.starblink.android.basic.network.base.SkGqlClient
import com.starblink.rocketreserver.ReadSystemMessageMutation
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

object MessageManager {

    /**
     * 读取系统消息
     * refreshState 刷新状态
     * resultCallback 接口成功回调
     */
    fun readSystemMessage(
        ctx: Context,
        messageId: String,
        resultCallback: (
            readSystemMessage: Boolean,
        ) -> Unit,
    ) {
        CoroutineScope(Dispatchers.IO).launch {
            val response = SkGqlClient.skMutation(
                ReadSystemMessageMutation(messageId)
            )
            if (response?.data != null && response.data!!.readSystemMessage != null) {
                MainScope().launch {
                    resultCallback(response.data!!.readSystemMessage!!)
                }
            }
        }
    }
}